package com.hnhs.controller;

import com.hnhs.mapper.CateProScreenDao;
import com.hnhs.model.CateproInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/")
public class CateProScreenController {

    @Autowired
    private CateProScreenDao cateProScreenDao;

    @GetMapping("catepropie")
    public List<Map<String,Object>> selectcatepro(){
        List<CateproInfo> selectcatepro = cateProScreenDao.selectcatepro();
        List<Map<String,Object>> mapList= new ArrayList<>();
        for (CateproInfo cateproInfo : selectcatepro) {
            if(cateproInfo.getProduct_count()==0){
                continue;
            }
            Map<String,Object> map=new HashMap<>();
            map.put("name",cateproInfo.getCategory_name());
            map.put("value",cateproInfo.getProduct_count());
            mapList.add(map);
        }
        return mapList;
    }

    @GetMapping("cateprobar")
    public List<Map> selectBar(){
      return  cateProScreenDao.selectBar();
    }
}
